import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:fluttermodule/view/AppNavi.dart';
import 'color/MyColor.dart';
import 'model/User.dart';
import 'color/MyUserTool.dart';
import 'dart:convert';
class LoginCtrl extends StatefulWidget{
  LoginCtrl({Key key, this.title}) : super(key: key);
    final title;
    @override
    State<StatefulWidget> createState() {
      return _LoginCtrlState();
    }
}

class _LoginCtrlState extends State<LoginCtrl> {
  TextEditingController account = TextEditingController();
  TextEditingController pwd = TextEditingController();
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750/2, height: 1334/2);
    return Scaffold(
      appBar: AppNavi(
        title: widget.title,
        backgroundColor: MyColor.AppColor,
        textColor: MyColor.AppFFFFFF,
      ),
      body: Center(
        child: new Column(
          children: <Widget>[
            new Container(
              margin: EdgeInsets.only(top: 20,left: 15,right: 15) ,
              height: 60,
              child: new TextField(
                autocorrect: true,
                obscureText: false,
                controller: account,
                decoration: InputDecoration(
                    labelText: "账号",
                    hintText: "用户名或者邮箱",
                    prefixIcon: Icon(Icons.person)
                ),
              ),
            ),
            new Container(
              margin: EdgeInsets.only(top: 20,left: 15,right: 15) ,
              height: 60,
              child: new TextField(
                autocorrect: true,
                obscureText: true,
                controller: pwd,
                decoration: InputDecoration(
                    labelText: "密码",
                    hintText: "登录密码",
                    prefixIcon: Icon(Icons.lock)
                ),
              ),
            ),
            new Container(
              margin: EdgeInsets.only(top: 20) ,
              width: ScreenUtil.screenWidthDp - 30,
              height: 45,
              child: new RaisedButton(
                onPressed:(){

                  if (account.text.length > 0 && pwd.text.length > 0){
                    String group='{"name": "Nancy","email": "Nancy@example.com","age":"30","phone":"15160023363","token":"111111qqqqqqq"}';
                    Map<String ,dynamic> map = json.decode(group);
                    User user = User.fromJson(map);
                    MyUserTool.saveData(user);
                    Navigator.of(context).pop();
                  }
                },
                child: Text("登录"),
                color: MyColor.AppColor,
                textColor: MyColor.AppFFFFFF,
              ),
            )
          ],
        ),
      ),
    );
  }
}